﻿<?xml version="1.0"?>

<!--   **********************************************************************   
                                                                           
       DWML.xsd - Top level XML Schema for Digital Weather Markup Language   

       John L. Schattel          MDL                4 August 2004  
       Red Hat Linux                                Apache Server  
       
       Paul Hershberg            MDL                11 July 2007
         -Added keyref for new <moreWeatherInformation> element.

   <xsd:include schemaLocation="http://graphical.weather.gov/xml/DWMLgen/schema/meta_data.xsd" />
   <xsd:include schemaLocation="http://graphical.weather.gov/xml/DWMLgen/schema/ndfd_data.xsd" />

      *************************************************************************   -->

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:include schemaLocation="http://graphical.weather.gov/xml/DWMLgen/schema/meta_data.xsd" />
  <xsd:include schemaLocation="http://graphical.weather.gov/xml/DWMLgen/schema/ndfd_data.xsd" />

  <xsd:simpleType name="latLonListType">
    <xsd:restriction base="xsd:string">
      <xsd:annotation>
        <xsd:documentation xml:lang="en">
          This expression enforces a space delimited list
          of latitude longitude pairs.  The latitude and
          longitude values are delimited by a comma
          (i.e. 38.00,-100.00 40.00,-78.00)
        </xsd:documentation>
      </xsd:annotation>
      <xsd:pattern value="[\-]?\d{1,2}\.\d+,[\-]?\d{1,3}\.\d+( [\-]?\d{1,2}\.\d+,[\-]?\d{1,3}\.\d+)*" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="cityNameListType">
    <xsd:restriction base="xsd:string">
      <xsd:annotation>
        <xsd:documentation xml:lang="en">
          This expression enforces a coma delimited list city names.
          The city names are ordered to match the cities latitude
          and longitude value in the accompanying latLonListType element
          (i.e. Dallas,Los Angeles,Salt Lake City)
        </xsd:documentation>
      </xsd:annotation>
      <xsd:pattern value="[a-zA-Z'\-]*( ?[a-zA-Z'\-]*)*,[A-Z][A-Z](\|[a-zA-Z'\-]*( ?[a-zA-Z'\-]*)*,[A-Z][A-Z])*" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:element name="dwml">
    <xsd:complexType>
      <xsd:choice>
        <xsd:sequence>
          <xsd:element name="head" type="headType" minOccurs="1" maxOccurs="1" />
          <xsd:element name="data" type="dataType" minOccurs="1" maxOccurs="unbounded">
            <xsd:keyref name="applicable-locationKey" refer="locationKey">
              <xsd:selector xpath="data/parameters" />
              <xsd:field xpath="@applicable-location" />
            </xsd:keyref>
            <xsd:keyref name="moreWeatherInformationKey" refer="locationKey">
              <xsd:selector xpath="data/moreWeatherInformation" />
              <xsd:field xpath="@applicable-location" />
            </xsd:keyref>
            <xsd:keyref name="applicable-timeKey" refer="timeKey">
              <xsd:selector xpath="data/parameters/*" />
              <xsd:field xpath="@time-layout" />
            </xsd:keyref>
            <xsd:keyref name="applicable-categoriesKey" refer="categoriesKey">
              <xsd:selector xpath="data/parameters/*" />
              <xsd:field xpath="@applicable-categories" />
            </xsd:keyref>
            <xsd:key name="locationKey">
              <xsd:selector xpath=".//location" />
              <xsd:field xpath="location-key" />
            </xsd:key>
            <xsd:key name="timeKey">
              <xsd:selector xpath=".//time-layout" />
              <xsd:field xpath="layout-key" />
            </xsd:key>
            <xsd:key name="categoriesKey">
              <xsd:selector xpath=".//categories" />
              <xsd:field xpath="categories-key" />
            </xsd:key>
          </xsd:element>
        </xsd:sequence>
        <xsd:sequence>
          <xsd:element name="minResolution" type="xsd:decimal" minOccurs="0" maxOccurs="1" />
          <xsd:element name="latLonList" type="latLonListType" />
          <xsd:element name="cityNameList" type="cityNameListType" minOccurs="0" maxOccurs="1" />
        </xsd:sequence>
      </xsd:choice>
      <xsd:attribute name="version" type="xsd:string" default="1.0" />
    </xsd:complexType>
  </xsd:element>

</xsd:schema>
